import os

files = os.listdir("D:\\tattoo\\")
links = []
for file in files:
    if ".png" in file or ".jpg" in file:
        filelist = file.split("_")
        links.append("[source](https://www.pixiv.net/artworks/"+filelist[0].strip(".")+")")
images = []
for i in range(len(links)):
    images.append("![img]("+str(i).zfill(3)+")")
f = open("D:\\tattoo\\tattoo.md","w",encoding="utf-8")
column = 4
ColumnNum = 1
TableHead1 = "|"
TableHead2 = "\n|"
while ColumnNum <= column:
    TableHead1 += "picture"+str(ColumnNum)+"|"
    TableHead2 += " -------- |"
    ColumnNum += 1
TableHead = TableHead1+TableHead2+"\n"
f.write(TableHead)
num = 0
while num < len(files):
    if num % column == 0:
        if num != 0:
            f.write("\n|")
        if num == 0:
            f.write("|")
    if num % 8 < 4:
        f.write(images[(num//8) * 4 +  num % 4]+"|")
    elif num % 8 > 3:
        f.write(links[(num//8) * 4 +  num % 4]+"|")
    num += 1
f.close()